clear all;
clear;
image=imread("fig6.tif");
% 添加椒盐噪声
K1 = imnoise(image,'salt & pepper',0.05);
result1=medfilt2(K1,[3 3]);
result2=medfilt2(K1,[5 5]);
result3=medfilt2(K1,[9 9]);
h1=fspecial("average",[3,3]);
result4=imfilter(K1,h1);
h2=fspecial("average",[5,5]);
result5=imfilter(K1,h2);
h3=fspecial("average",[9,9]);
result6=imfilter(K1,h3);
subplot(3,3,1),imshow(image),title("原图像");
subplot(3,3,2),imshow(result1),title("均值[3 3]");
subplot(3,3,3),imshow(result2),title("均值[5 5]");
subplot(3,3,4),imshow(result3),title("均值[9 9]");
subplot(3,3,5),imshow(result4),title("中值[3 3]");
subplot(3,3,6),imshow(result5),title("中值[5 5]");
subplot(3,3,7),imshow(result6),title("中值[9 9]");